package io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @Author Justin Parker
 * @Date 2024/7/16 0016 14:42
 * @Version 1.0
 */
public class ReadStringDemo02 {
    public static void main(String[] args) throws IOException {
        //1.构建文件输入流对象
        // File file = new File("./f1.text");
        // long size = file.length();
        // FileInputStream fis = new FileInputStream(file);
        File file = new File("./f1.text");
        //读取文件内容（将数据读取到字节数组中）
        FileInputStream fis = new FileInputStream(file);

//        byte[] b = new byte[(int)size];
        byte[] b = new byte[fis.available()]; //fis.available()获取流中有效字节数
        int len = fis.read(b);
       //3. 将字节数组内容转换为字符串并输出
        String str = new String(b, 0, len);
        System.out.println(str);
        //4.关闭流
        fis.close();


    }
}
